package network.byteConversions;
import tools.Point;
public class ByteArrayReader {
	private byte data[];
	private ByteMapper bmapper;
	public ByteArrayReader(ByteMapper bmap, byte data[]) {
		this.data = data;
		bmapper = bmap;
	}
	public ByteArrayReader(ByteMapper bmap) {
		this.bmapper = bmap;
	}
	public void setData(byte data[]) {
		this.data = data;
	}
	public int readInt(String vname) {
		int offs = bmapper.getOffset(vname);
		int i = ByteConverter.fourBytesToInt(data[offs], data[offs + 1], data[offs + 2], data[offs + 3]);
		return i;
	}
	public float readFloat(String vname) {
		int offs = bmapper.getOffset(vname);
		byte fdata[] = {data[offs], data[offs + 1], data[offs + 2], data[offs + 3]};
		float f = ByteConverter.bytesToFloat(fdata);
		return f;
	}
	public boolean readBoolean(String vname) {
		int offs = bmapper.getOffset(vname);
		return ByteConverter.byteToBoolean(data[offs]);
	}
	public char readChar(String vname) {
		int offs = bmapper.getOffset(vname);
		return ByteConverter.byteToChar(data[offs]);
	}
	public Point readPoint(String vname) {
		int offs = bmapper.getOffset(vname);
		byte pdata[] = {data[offs], data[offs + 1], data[offs + 2], data[offs + 3], data[offs + 4], data[offs + 5], data[offs + 6], data[offs + 7]};
		return ByteConverter.bytesToPoint(pdata);
	}
	public long readLong(String vname) {
		int offs = bmapper.getOffset(vname);
		byte ld[] = new byte[8];
		for (int i = 0; i < 8; i++)
			ld[i] = data[offs + i];
		return ByteConverter.bytesToLong(ld);
	}
}
